//
//  AppDelegate.swift
//  MPSinaWeibo
//
//  Created by DaVinci on 16/4/6.
//  Copyright © 2016年 DaVinci. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
//       let account = MPUserAccountViewModel.sharedAccountViewModel.loadUserInfo()
        
        

        
        
        window?.frame = UIScreen.mainScreen().bounds
        
//        window?.rootViewController = MPMainController()
        
//        window?.rootViewController = MPWelcomeController()
       
        window?.rootViewController = defaultViewController()
        
        window?.makeKeyAndVisible()
        
        registerNotification()
        
        setNavBarThemeColor()

        
        return true
    }
   
    //注册通知
    
    func registerNotification(){
    
       NSNotificationCenter.defaultCenter().addObserver(self, selector: "ChangeRootViewController:", name: notificationName, object: nil)
    
    }
    
    //实现通知方法
    @objc private func ChangeRootViewController(notify: NSNotification){
        
    
        if notify.object != nil{
           //从欢迎页面发来的通知
           window?.rootViewController = MPMainController()
            
        }else{
           //从授权页面发来的通知
           window?.rootViewController = MPWelcomeController()
        }
    }
    
    private func setNavBarThemeColor(){
    
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
    }
    
    private func defaultViewController() -> UIViewController {
    
        return  MPUserAccountViewModel.sharedAccountViewModel.userLogin ? MPWelcomeController(): MPMainController()
    
    }


}

